<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="public/css/login.css" />
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  </head>

  <body>
    <div class="outer">
      <div class="con">
        <img src="public/img/logo.png" alt="" />
        <h2>尚硅谷学生管理系统注册账号</h2>
        <form class="ipts">
          <input type="text" id="user" placeholder="用户名" />
          <input type="oassword" id="pass" placeholder="密码" />
          <button id="btn">登录</button>
        </form>
      </div>
    </div>
    <script>
      const oBtn = document.getElementById("btn");
      const oUser = document.getElementById("user");
      const oPass = document.getElementById("pass");
      axios.interceptors.response.use(
        (response) => {
          // Do something before response is sent
          if (response.data.code == "100000") {
            return response.data.msg;
          } else {
            return Promise.reject(response.data.msg);
          }
        },
        (error) => {
          // Do something with response error
          return Promise.reject(error);
        }
      );
      oBtn.onclick = function () {
        const user = oUser.value;
        const pass = oUser.value;
        if (user === "" || pass === "") {
          alert("不能为空");
          return false;
        }

        axios
          .post("/login", {
            user,
            pass,
          })
          .then((res) => {
            alert(res);
            location.href = "./center.html";
          })
          .catch((err) => {
            alert(err);
          });

        return false;
      };
    </script>
  </body>
</html>
